/**
 * Created by YAAP on 2017/8/1.
 */
define(['edit-map','block-detail','houseno-list','block-surrounding-supporting','block-property-document'],(editMap,BlockDetail,HousenoList,BlockSurroundingSupporting,BlockPropertyDocument)=>{
    var template = `
      
            <div class="plotInfoModal" style="width: 1100px;" v-show="show">
                <div class="message-box addPlotWrap draggable" style="width: 1100px;">
                    <div class="modal-content clearfix">
                        <div class="modal-content-left">
                            <div class="mcl-top clearfix">
                                <span class="mcl-title">小区资料</span>
                                <Tabs value="name1"  :animated="false" >
                                    <Tab-pane label="楼盘" name="name1">
                                        <!-- 不可修改的楼盘tab-->
                                      
                                        <block-detail > </block-detail>
                                        <!-- 隐藏新增小区资料的内容-->
                                    </Tab-pane>
                            <!--<Tab-pane label="批量房号" name="tab_houseno">

                                    <houseno-list :housenolist="blockinfo.housenoList"></houseno-list>


                            </Tab-pane> -->
                                    <Tab-pane label="周边配套" name="name3">
                                    <block-surrounding-supporting></block-surrounding-supporting>
                                    </Tab-pane>
                                    <Tab-pane label="物业文档" name="name4">
                                        <block-property-document></block-property-document>
                                    </Tab-pane>
                                </Tabs>
                            </div>
                            <!-- 底部按钮-->
                            <div class="mcl-plotFooter">
                                <div class="plotFooter-left left">
                                    <a href="javascript:;"></a>
                                    <span>锁定楼盘</span>
                                </div>
                                <div class="plotFooter-rihgt right">
                                    <i-button @click="createNewBlock" class="addPlotBtn"><i></i>添加新小区</i-button>
                                    
                                    <i-button @click="saveBlock()" class="saveEditBtn"><i></i>保存修改</i-button>
                                    <i-button class='cancelBtn' @click="closeModal"><i></i>取消</i-button>
                                    
                                </div>
                            </div>
                        </div>
                        <!-- 右边-->
                        <div class="modal-content-right">
                            <div class="mcr-top">
                                <div class="top-title left">小区地图</div>
                                <div class="right-icon right">
                                    <a href="javascript:;" class="clickBig"></a>
                                    <a href="javascript:;" class="clickMin"></a>
                                    <a href="javascript:;" class="clickClose" v-on:click="closeModal"></a>
                                </div>
                            </div>
                            <div id="mcr-map" class="mcr-content"></div>
          <div class="retrieval_button">
            <div class="school_button" @click="showSchoolMarker(0)">
              <div class="school_img"></div>
              <strong>学校</strong></div>
            <div class="hospital_button" @click="showSchoolMarker(1)">
              <div class="hospital_img"></div>
              <strong>医院</strong></div>
            <div class="Supermarket_button" @click="showSchoolMarker(2)">
              <div class="Supermarket_img"></div>
              <strong>超市</strong></div>
            <div class="Market_button" @click="showSchoolMarker(3)">
              <div class="Market_img"></div>
              <strong>商场</strong></div>
            <div class="Busstop_button" @click="showSchoolMarker(4)">
              <div class="Busstop_img"></div>
              <strong>公交站</strong></div>
          </div>
          <div id="r-result">
            <div class="r-result_img"></div>
            <input type="button"  :value="editPoint" @click="handleEditMarker" /></div>
          <div id="control">
            <div class="control_img"></div>
            <button @click="handleEditMapRange">{{editHouseText}}</button></div>
                        </div>
                    </div>
                    <div class="details-but">
                        <div class="details-but-left"></div>
                        <a href="#" class="shuaxin"></a>
                        <div class="details-but-right"></div>
                    </div>
                </div>
                <div class="zhezhao" v-on:click="closeModal" v-show="show"></div>
            </div>
`;
    var initBlockInfo = {
        realEstate: {
            BlockModel: {
                "BuildingMustSelect": false,
                "RoomNoMustSelect": false,
                "PropertyFee":0,
                "AveragePrice": {
                    "Price": {
                        "Amount":0,
                        "CurrencyName": "\uffe5",
                        "CurrencyValue": 1
                    },
                    "UnitName": "",
                    "UnitValue": 0
                },
                "Alias": "",
                "EnglishName": "",
                "Pinyin": "",
                "EnglishAddress": "",
                "PropertyCompany": "",
                "PropertyUsageValue": 0,
                "PropertyUsageName": "",
                "LandNo": "",
                "Land": "",
                "OuterWall": "",
                "ConstructionType": "",
                "HouseholdAmount": 0,
                "BuiltTime": (new Date()).getFullYear() + "-" + ((new Date()).getMonth() + 1) + "-" + (new Date()).getDate(),
                "BuildingAmount": 0,
                "SubmitTime": (new Date()).getFullYear() + "-" + ((new Date()).getMonth() + 1) + "-" + (new Date()).getDate(),
                "Id": "",
                "SortNo": 0,
                "Name": "",
                "ParentNodeName": "",
                "ParentNodeId": "",
                "ChildrenNode": []
            },
            "BuildingArea": {"Amount":0,"Unit":0},
            "Id": "",
            "Name": "",
            "Pinyin": "",
            "Memo": null,
            "OrganizationNodeId": null,
            "CustomAreaId": null,
            "CustomAreaName": null,
            "AddressAdministrativeDivisionCode": "",
            "AddressDetail": "",
            "AddressSummary": "",
            "MapArea": null,
            "PropertyTypeValue": 0,
            "PropertyTypeName": "Office",
            "CreatedTime": ""
        },
        housenoList: [],
        surroundSupporting: [],
        propertyDocuments: []
    };

    var BlockModal = {
        name: "block-modal",
        template: template,
        components: {
            BlockDetail: BlockDetail,
            HousenoList: HousenoList,
            BlockSurroundingSupporting: BlockSurroundingSupporting,
            BlockPropertyDocument: BlockPropertyDocument,
        },

        data: function () {
            return {
                editPoint: '修改坐标点',
                editHouseText: '绘制房源范围',
                amap: {},
                blockRules: {
                    name2: [
                        {required: true, message: "required"}
                    ]
                },

                block: {block_id: -1},
                blocktestinfo: {name: "testname"},
                show: false,
                blockinfo: initBlockInfo,
                reposonse: {},
                progress: 0

            }
        },


        methods: {
            handleEditMarker: function () {
                this.amap.editMarker()
                if (this.amap.isEditMarker) {
                    this.editPoint = '保存坐标点'
                } else {
                    this.editPoint = '修改坐标点'
                }

            },
            handleEditMapRange: function () {
                this.amap.editPolygon()
                if (this.amap.isEditPolygon) {
                    this.editHouseText = '保存绘制范围'
                } else {
                    this.editHouseText = '绘制房源范围'
                }

            },
            showSchoolMarker: function (index) {
                switch (index) {
                    case 0: {
                        this.amap.search('学校')
                        break
                    }
                    case 1: {
                        this.amap.search('医院')
                        break
                    }
                    case 2: {
                        this.amap.search('超市')
                        break
                    }
                    case 3: {
                        this.amap.search('商场')
                        break
                    }
                    case 4: {
                        this.amap.search('公交车站')
                        break
                    }
                }
            },
            closeModal: function () {

                this.show = false;
            },
            createNewBlock: function () {
                window.bus.$emit("editblock",null);
               // this.blockinfo = initBlockInfo
            },


            saveBlock: function () {
                // detail.saveblockdetail()
                window.bus.$emit("saveblock",null);


            }
        },

        mounted: function () {
            var that = this;
            this.amap = new editMap('mcr-map')
            window.bus.$on("editblock", function (block) {
                that.show = true;
             //   that.blockinfo=block==null?initBlockInfo:block;
            });

            window.bus.$on("block_save_success", function (data) {

                that.show = false;
            });

        }
    }
    return BlockModal
})
